package com.chinasoft.workmanage.common.utils;

import sun.misc.BASE64Encoder;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by Administrator on 2017/3/30.
 */
public class Md5Encryption {
    /**
     * MD5加密
     * @param str 要加密的字符串
     * @return
     */
    public static String EncoderByMd5(String str){
        String newstr = "";
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            BASE64Encoder base64en = new BASE64Encoder();
            newstr=String.valueOf(md5.digest(str.getBytes("utf-8")));
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }finally {
            return newstr;
        }
    }
    public static void main(String[] args){
        System.out.println(EncoderByMd5("1"));
    }
}
